package com.main.heath.servcie.impl;

import com.alibaba.fastjson.JSONObject;
import com.main.heath.mapper.PingdataExtendMapper;
import com.main.heath.po.PingData;
import com.main.heath.servcie.PingDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by heathhose on 16-11-28.
 */
@Service
public class PingDataServiceImpl implements PingDataService {
    @Autowired
    private PingdataExtendMapper pingdataExtendMapper;

    @Override
    public PingData getPingInfo(String ipAddress) {
        PingData pingData = pingdataExtendMapper.getPingInfo(ipAddress);
        if(pingData  == null)
            return null;
        else{
            pingdataExtendMapper.setPingStatus(pingData.getId().intValue());
            return pingData;
        }
    }

    @Override
    public List<PingData> getAllPingInfo() {
        return pingdataExtendMapper.getAllPingInfo();
    }


    @Override
    public int setPingStatus(int id) {
        return pingdataExtendMapper.setPingStatus(id);
    }

    @Override
    public int deletePingRc(int id) {
        return 0;
    }

    @Override
    public int deleteAllPingInfo() {
        return pingdataExtendMapper.deleteAllPingInfo();
    }

    @Override
    public JSONObject analysisPing(String ip) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("min",pingdataExtendMapper.analyMin(ip));
        jsonObject.put("max",pingdataExtendMapper.analyMax(ip));
        jsonObject.put("avg",pingdataExtendMapper.analyAvg(ip));
        jsonObject.put("mdev",pingdataExtendMapper.analyMdev(ip));
        return  jsonObject;
    }

    @Override
    public Double analyPacketLoss(String ip) {

        return pingdataExtendMapper.analyPacketLoss(ip);
    }

    @Override
    public Double analyReachable(String ip) {
        return pingdataExtendMapper.analyReachable(ip);
    }


}
